import { NeedToLoginCodeList } from '@/utils/constant'
import { urls } from '@/security/paths'
import { redirectTimeout } from '@/security/router'

uni.addInterceptor('request', {

    invoke(args: any) {
       const url:string = args.url
       if(!url.startsWith("http")){
          args.url = import.meta.env.VITE_BASE_URL +  import.meta.env.VITE_URL_PREFIX +  url
       } 
    },


    complete(res) {
      if(NeedToLoginCodeList.includes(res.data.code)){
        redirectTimeout(urls.Loin)
      }
    }
  })


uni.addInterceptor('uploadFile', {

    invoke(args) {
       const url:string = args.url
       if(!url.startsWith("http")){
          args.url = import.meta.env.VITE_BASE_URL +  import.meta.env.VITE_URL_PREFIX +  url
       } 
    },

    complete(res) {
      if(NeedToLoginCodeList.includes(res.data.code)){
        redirectTimeout(urls.Loin)
      }
    }
}) 